import { Application } from "egg";
import { Schema } from "mongoose";
import * as AutoIncrementFactory from "mongoose-sequence";
export interface PrivilegesTypeProps {
  id?: number;
  privileges_type_name: string;
  privileges_type_code: string;
  is_delete: boolean;
}
function initPrivilegesTypeModel(app: Application) {
  const AutoIncrement = AutoIncrementFactory(app.mongoose);
  // 创建数据模型
  const PrivilegesTypeSchema = new Schema<PrivilegesTypeProps>(
    {
      privileges_type_name: { type: String, unique: true, required: true },
      privileges_type_code: { type: String, unique: true, required: true },
      is_delete: { type: Boolean, default: false },
    },
    {
      timestamps: true,
      toJSON: {
        transform(_doc, ret) {
          delete ret.__v;
        },
      },
    }
  );
  PrivilegesTypeSchema.plugin(AutoIncrement, {
    inc_field: "id",
    id: "Privileges_type_counter",
  });
  return app.mongoose.model<PrivilegesTypeProps>(
    "PrivilegesType",
    PrivilegesTypeSchema
  );
}
export default initPrivilegesTypeModel;
